#ifndef BPlusTree_h
#define BPlusTree_h
 
#include "inc.h"
#include "pager.h"
 
//#define M ((int) (PAGE_SIZE / (sizeof(record_t) + sizeof(slot_t)) - 1))
#define M (3)
#define LIMIT_M_2 (M % 2 ? (M + 1)/2 : M/2)
 
typedef struct BPlusNode *BPlusTree, *Position;
typedef int KeyType;
struct BPlusNode {
    int KeyNum;
    KeyType Key[M + 1];
    BPlusTree Children[M + 1];
    BPlusTree Next;
    page_t page;
};
 
BPlusTree InitTree(pager_t *pager);
BPlusTree InsertToTree(BPlusTree T, KeyType Key, pager_t *pager, record_t *record, int *flag);
BPlusTree RemoveFromTree(BPlusTree T, KeyType Key);
Position SearchFromTree(BPlusTree T, KeyType key);
BPlusTree DestroyTree(BPlusTree T);
void Travel(BPlusTree T);
void TravelData(BPlusTree T);
 
#endif 
